package com.buss.FrontController;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.jeecgframework.core.common.controller.BaseController;
import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
import org.jeecgframework.core.common.model.json.AjaxJson;
import org.jeecgframework.core.util.StringUtil;
import org.jeecgframework.tag.vo.datatable.SortDirection;
import org.jeecgframework.web.image.controller.ImagesController;
import org.jeecgframework.web.system.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import com.buss.areainfo.entity.AreaInfoEntity;
import com.buss.areainfo.service.impl.AreaInfoServiceImpl;
import com.buss.artcomments.entity.BnsArticleCommentsEntity;
import com.buss.artcomments.service.BnsArticleCommentsServiceI;
import com.buss.article.entity.BnsArticleEntity;
import com.buss.article.service.BnsArticleServiceI;
import com.buss.articlegroup.entity.ArticleGroupInfoEntity;
import com.buss.dt.entity.BnsDtEntity;
import com.buss.dt.service.BnsDtServiceI;
import com.buss.photo.entity.BnsAlbumEntity;
import com.buss.photo.entity.BnsPhotoEntity;
import com.buss.photo.service.BnsAlbumServiceI;
import com.buss.photo.service.BnsPhotoServiceI;
import com.buss.quickentry.entity.QuickEntryEntity;
import com.buss.share.entity.BnsShareEntity;
import com.buss.share.service.BnsShareServiceI;
import com.buss.shuoshuo.entity.BnsShuoshuoEntity;
import com.buss.shuoshuo.service.BnsShuoshuoServiceI;
import com.buss.user.entity.BnsUserFriendEntity;
import com.buss.user.entity.BnsUsersInfoEntity;
import com.buss.user.service.BnsUserFriendServiceI;
import com.buss.group.entity.BnsGroupClassEntity;
import com.buss.group.entity.BnsGroupEntity;
import com.buss.log.entity.BnsLogEntity;
import com.buss.log.service.BnsLogServiceI;
import com.buss.logclass.entity.BnsLogClassEntity;
import com.buss.logclass.service.BnsLogClassServiceI;
import com.buss.message.entity.BnsMessageEntity;
import com.buss.message.service.BnsMessageServiceI;

/**
 * 首页控制层
 * @author hlg
 * @Date 2016-08-03
 */
@Scope("prototype")
@Controller
@RequestMapping("/indexController")
public class IndexController extends BaseController {
	private static final Logger logger = Logger.getLogger(IndexController.class);
	private static String imgUrl;
	private String message;
	
	@Autowired
	private BnsShuoshuoServiceI bnsShuoshuoService;
	@Autowired
	private BnsLogServiceI bnsRizhiService;
	@Autowired
	private BnsArticleCommentsServiceI bnsRzCommentsService;
	@Autowired
	private SystemService systemService;
	@Autowired
	private BnsLogClassServiceI bnsLogClassService;
	@Autowired
	private BnsUserFriendServiceI bnsUserFriendService;
	@Autowired
	private BnsAlbumServiceI bnsAlbumService;
	@Autowired
	private BnsPhotoServiceI bnsPhotoService;
	@Autowired
	private BnsMessageServiceI bnsMessageService;
	@Autowired
	private BnsShareServiceI bnsShareService;
	@Autowired
	private BnsArticleCommentsServiceI bnsArtComService;
	@Autowired
	private BnsDtServiceI bnsDtService;
	

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	@Autowired
	public void setSystemService(SystemService systemService) {
		this.systemService = systemService;
	}

	/**
	 * 首页
	 * @return
	 */
	@RequestMapping(params = "index")
	public ModelAndView index(Model model,HttpServletRequest request) {
		String pathStr = "front/index";
		List<AreaInfoEntity> areInfoLists = systemService.loadAll(AreaInfoEntity.class);
		List<ArticleGroupInfoEntity> articleGroupLists = systemService.loadAll(ArticleGroupInfoEntity.class);
		List<BnsArticleEntity> totalArticle = systemService.loadAll(BnsArticleEntity.class);
		List<BnsUsersInfoEntity> userList = systemService.loadAll(BnsUsersInfoEntity.class);
		
		List todayArticletotal =systemService.findForJdbc("select * from bns_article where to_days(create_date) = to_days(now())");
		List yesterdayArticletotal =systemService.findForJdbc("select * from bns_article where TO_DAYS(NOW())-TO_DAYS(create_date) = 1");
		
		List<QuickEntryEntity> quickEntryList = systemService.loadAll(QuickEntryEntity.class);
		
		model.addAttribute("quickEntryList", quickEntryList);
		model.addAttribute("areInfoLists", areInfoLists);
		model.addAttribute("articleGroupLists", articleGroupLists);
		model.addAttribute("totalArticle", totalArticle.size());
		model.addAttribute("todayArticletotal", todayArticletotal.size());
		model.addAttribute("yesterdayArticletotal", yesterdayArticletotal.size());
		model.addAttribute("userNum", userList.size());
		model.addAttribute("backgroundColor", "1");
		return new ModelAndView(pathStr);
	}
	
	/**
	 * 群组
	 * @return
	 */
	@RequestMapping(params = "group")
	public ModelAndView group(Model model,HttpServletRequest request) {
		String pathStr = "front/group";
		//群组父类分类 systemService.findByProperty(BnsGroupClassEntity.class, "parentId", null);// 
		List<BnsGroupClassEntity> groupClassParentList=systemService.loadAll(BnsGroupClassEntity.class);
		//分父类，子类列表出来
		List<BnsGroupClassEntity> parentClassList=new ArrayList<BnsGroupClassEntity>();
		List<BnsGroupClassEntity> sonClassList=new ArrayList<BnsGroupClassEntity>();
		for(BnsGroupClassEntity entity : groupClassParentList){
			if(entity.getParentId()==null)
				parentClassList.add(entity);
			else {
				sonClassList.add(entity);
			}
		}
		for(BnsGroupClassEntity parentEntity : parentClassList){
			int groupAccount=0;
			List<BnsGroupClassEntity> childrens=new ArrayList<BnsGroupClassEntity>();
			for(BnsGroupClassEntity sonEntity : sonClassList){
				if(sonEntity.getParentId().equals(parentEntity.getId())){
					childrens.add(sonEntity);
					groupAccount+=sonEntity.getGroupAccount();
				}
			}
			parentEntity.setChildren(childrens); 
			parentEntity.setGroupAccount(groupAccount);
		} 
		model.addAttribute("groupClassList",parentClassList); 
		 
		//群组分类中的群组名称
		CriteriaQuery cq = new CriteriaQuery(BnsGroupEntity.class); 
		cq.eq("isRecommend", 1);	//推荐的群组
		cq.addOrder("createDate", SortDirection.desc);
		cq.setCurPage(0);
		cq.setPageSize(50);
		cq.add();
		List<BnsGroupEntity> groupList =systemService.getListByCriteriaQuery(cq, true);
		model.addAttribute("groupList",groupList);
		//积分排行--8条
		List<Map<String, Object>> groupJf =systemService.findForJdbc("SELECT id,group_name,group_integral FROM bns_group order by group_integral desc limit 8 ", new Object[]{});
		List<BnsGroupEntity> groupJfList=new ArrayList<BnsGroupEntity>();
		for(int i=0;i<groupJf.size();i++){
			Map map=groupJf.get(i);
			BnsGroupEntity group=new BnsGroupEntity();
			group.setId(map.get("id").toString());//group_headerimg
			group.setGroupName(map.get("group_name").toString());
			group.setGroupIntegral(Integer.parseInt(map.get("group_integral").toString()));
			groupJfList.add(group);
		}
		model.addAttribute("groupJfList",groupJfList);
		
		//群组焦点--文章内容标题
		List<Map<String, Object>> groupArticle=systemService.findForJdbc("SELECT id,title,create_date from bns_group_article where is_recommend=1 order by create_date desc limit 10 ", new Object[]{});
		request.setAttribute("groupArticle", groupArticle);
		
		model.addAttribute("backgroundColor", "2");
		return new ModelAndView(pathStr);
	}
	
	//上传文件方法
	@RequestMapping(params="ajaxUpload")
	@ResponseBody
	public String ajaxUpload(HttpServletRequest request) throws IllegalStateException, IOException {
		MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		String fileName = "";
		String uploadPath = "upload/";
		String path =request.getSession().getServletContext().getRealPath("/")+uploadPath;  
		String realPath = "";
		String oldName = "";
		for (Iterator<String> it = multipartRequest.getFileNames(); it.hasNext();) {
			String key = it.next();
			MultipartFile mulfile = multipartRequest.getFile(key);
			fileName = mulfile.getOriginalFilename();
			oldName = fileName.substring(0,fileName.lastIndexOf("."));
			fileName = rewriteFileName(fileName);
			File file = new File(path + fileName);
			mulfile.transferTo(file);
		}
		realPath = "{\"imagePath\":\""+uploadPath+fileName+"\",\"oldName\":\"" + oldName + "\"}";
		imgUrl = uploadPath+fileName;
		
		return realPath;
	}

	//文件名称处理
	private String rewriteFileName(String fileName) {
		int pointIndex = fileName.lastIndexOf(".");
		StringBuffer fileNameBuffer = new StringBuffer();
		fileNameBuffer.append((new Date()).getTime()+"_"+fileName.substring(0,pointIndex));
		fileNameBuffer.append(fileName.substring(pointIndex));
		return fileNameBuffer.toString();
	}

	//预览，获取图片流
	@RequestMapping(params="readImage", produces = "text/plain;charset=UTF-8")
	public void readImage(HttpServletRequest request, HttpServletResponse response){
		String imagePath = request.getSession().getServletContext().getRealPath("/")+request.getParameter("imagePath");
		try{
			File file = new File(imagePath);
			if (file.exists()) {
				DataOutputStream temps = new DataOutputStream(response.getOutputStream());
				DataInputStream in = new DataInputStream(new FileInputStream(imagePath));
				byte[] b = new byte[2048];
				while ((in.read(b)) != -1) {
					temps.write(b);
					temps.flush();
				}
				in.close();
				temps.close();
			} 
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 家园
	 * @return
	 */
	@RequestMapping(params = "home")
	public ModelAndView home(Model model,HttpServletRequest request) {
		String pathStr = "front/home";
		String userName = (String) request.getSession().getAttribute("userName");
		Object mymbId= request.getSession().getAttribute("mbId");
		
		
		//判断登录是否超时  --zyb
		if(!StringUtil.isNotEmpty(mymbId)){	
			userName = "";
			pathStr = "front/login";	
		}else{			
//			int userId = (Integer)request.getSession().getAttribute("mbId");
//			request.setAttribute("userId", userId);
				
			String what = request.getParameter("show");  //获取前台正处于哪个功能  --zyb
//			System.out.print("---------------------------what:"+what);
			
			//添加说说 --zyb
			String ss = request.getParameter("dt");
			if(ss!=null){  //  --zyb
				BnsShuoshuoEntity mySshuo = new BnsShuoshuoEntity();
				mySshuo.setCreateBy(mymbId.toString());
				mySshuo.setCreateName(userName);
				mySshuo.setContent(ss);
				mySshuo.setCreateDate(new Date());
				bnsShuoshuoService.save(mySshuo);
				
				//保存一条动态
				BnsDtEntity ssdt = new BnsDtEntity();
				ssdt.setUser1Id(Integer.valueOf(mymbId.toString()));
				ssdt.setUser1Name(userName);
				ssdt.setContent(ss);
				ssdt.setCreateDate(new Date());
				ssdt.setDtId(mySshuo.getId()); //保存分享id到动态对象id
				ssdt.setDtType("jl"); 	//动态类型：添加分享
				bnsDtService.save(ssdt);
				pathStr = "redirect:/indexController.do?home&show=ss_my";
			}
			
			//随便看看说说  --zyb
			if("ss_all".equals(what)){
				
				String page=request.getParameter("page");
				int pageParam=0;
				if(StringUtil.isEmpty(page))
					pageParam=0;
				else
					pageParam=Integer.parseInt(page);
				
				Long dataCount=0L;
				
				CriteriaQuery cqss = new CriteriaQuery(BnsShuoshuoEntity.class);
				//排序
				cqss.addOrder("createDate", SortDirection.desc);
				
				//分页
				cqss.setPageSize(10);
				cqss.setCurPage(pageParam);
				cqss.add();
				List<BnsShuoshuoEntity> allSshuoList = systemService.getListByCriteriaQuery(cqss, true);	
				int pageCount=0;
				dataCount = systemService.getCountForJdbcParam("select count(1) from bns_shuoshuo",null);
				if(dataCount.intValue()>0 && dataCount.intValue()%10==0)
					pageCount=dataCount.intValue()/10;
				else
					pageCount=dataCount.intValue()/10+1;
				
				request.setAttribute("pageCount",pageCount); 

				request.setAttribute("allSshuoList", allSshuoList);
				
			}
			//我的说说  --zyb
			if("ss_my".equals(what)){
				
				String page=request.getParameter("page");
				int pageParam=0;
				if(StringUtil.isEmpty(page))
					pageParam=0;
				else
					pageParam=Integer.parseInt(page);
				
				Long dataCount=0L;
				
				CriteriaQuery cqss = new CriteriaQuery(BnsShuoshuoEntity.class);
				cqss.eq("createBy", mymbId.toString());
				cqss.add();
				//排序
				cqss.addOrder("createDate", SortDirection.desc);
				//分页
				cqss.setPageSize(10);
				cqss.setCurPage(pageParam);
				cqss.add();
				List<BnsShuoshuoEntity> mySshuoList = systemService.getListByCriteriaQuery(cqss, true);	
				int pageCount=0;
				dataCount = systemService.getCountForJdbcParam("select count(1) from bns_shuoshuo where create_by = '"+mymbId+"'",null);
				if(dataCount.intValue()>0 && dataCount.intValue()%10==0)
					pageCount=dataCount.intValue()/10;
				else
					pageCount=dataCount.intValue()/10+1;
				
				request.setAttribute("pageCount",pageCount); 
				request.setAttribute("mySshuoList", mySshuoList);
				
			}
			//好友说说  --zyb
			if("ss_friend".equals(what)){
							
				//分页的相关参数  --zyb
				String page=request.getParameter("page");
				int pageParam=1;
				if(StringUtil.isEmpty(page))
					pageParam=1;
				else
					pageParam=Integer.parseInt(page);
				
				Long dataCount=0L;		//总共的数据数量
				int numInPage = 5;		//一页显示20个	--zyb
				List<Map<String, Object>> fSshuos = systemService.findForJdbc("select * from bns_shuoshuo where create_by = any(select friend_id from bns_user_friend where user_id = '"+mymbId+"' and is_gre = 1)"
						, pageParam
						, numInPage);
									
				//分页 											
				dataCount = systemService.getCountForJdbcParam("select count(1) from bns_shuoshuo where create_by = any(select friend_id from bns_user_friend where user_id = '"+mymbId+"' and is_gre = 1)",null);
				int pageCount=0;
				if(dataCount.intValue()>0 && dataCount.intValue()%numInPage==0)
					pageCount=dataCount.intValue()/numInPage;
				else
					pageCount=dataCount.intValue()/numInPage+1;
				request.setAttribute("pageCount",pageCount); 

				request.setAttribute("fSshuos", fSshuos);
			}
			
			/***************************  日志  --zyb ************************************/
			
				//我的日志列表  --zyb
				if("rz_my".equals(what)){
					
					String page=request.getParameter("page");
					int pageParam=0;
					if(StringUtil.isEmpty(page))
						pageParam=0;
					else
						pageParam=Integer.parseInt(page);
					
					Long dataCount=0L;
					CriteriaQuery cqp = new CriteriaQuery(BnsLogEntity.class);
					dataCount = systemService.getCountForJdbcParam("select count(1) from bns_log where create_by = '"+mymbId+"'",null);
					cqp.eq("createBy", mymbId.toString());
					cqp.add();
					
					//排序
					cqp.addOrder("createDate", SortDirection.desc);
					//分页
					cqp.setPageSize(10);
					cqp.setCurPage(pageParam);
					cqp.add();
					List<BnsLogEntity> myLogList = systemService.getListByCriteriaQuery(cqp, true);
					int pageCount=0;
					if(dataCount.intValue()>0 && dataCount.intValue()%10==0)
						pageCount=dataCount.intValue()/10;
					else
						pageCount=dataCount.intValue()/10+1;
					request.setAttribute("myLogList", myLogList);
					request.setAttribute("pageCount",pageCount); 
					
				}
				
				//随便看看日志列表  --zyb
				else if("rz_all".equals(what)){
					
					//######################## 评论  --zyb
					String rzCom = request.getParameter("rzCom");
					String rzId= request.getParameter("rzId");
//					System.out.print("--------------------rzCom:"+rzCom);
					if(rzCom != "" && rzCom != null){
						//添加评论  --zyb
						BnsArticleCommentsEntity logCom = new BnsArticleCommentsEntity();
						logCom.setCommentsType("0");
						logCom.setCommentsId("");
						logCom.setReplyTitle("");
						logCom.setReplyContent("");
						logCom.setArticleId(rzId);
						logCom.setCommentsContent(rzCom);				
						logCom.setCreateDate(new Date());
						logCom.setCreateBy(mymbId.toString());
						logCom.setCreateName(userName);
						//日志评论数+1  --zyb
						bnsRzCommentsService.save(logCom);
						BnsLogEntity plLog = bnsRizhiService.getEntity(BnsLogEntity.class, rzId);
						plLog.setPlNum(plLog.getPlNum() + 1);
						bnsRizhiService.save(plLog);
						
						//保存一条动态
						BnsDtEntity pldt = new BnsDtEntity();
						pldt.setUser1Id(Integer.valueOf(mymbId.toString()));
						pldt.setUser1Name(userName);
//						pldt.setTitle(rz_title);
						pldt.setContent(rzCom);
						pldt.setDtId(logCom.getId());		//保存日志id到动态对象id
						pldt.setCreateDate(new Date());
						pldt.setDtType("fbplly"); 			//动态类型：撰写日志
						bnsDtService.save(pldt);
					}
					
					//分页的相关参数  --zyb
					String page=request.getParameter("page");
					int pageParam=0;
					if(StringUtil.isEmpty(page))
						pageParam=0;
					else
						pageParam=Integer.parseInt(page);				
					Long dataCount=0L;
					CriteriaQuery cqp = new CriteriaQuery(BnsLogEntity.class);
					dataCount = systemService.getCountForJdbcParam("select count(1) from bns_log",null);
																
					//排序  --zyb
					cqp.addOrder("createDate", SortDirection.desc);
					//分页  --zyb
					cqp.setPageSize(10);
					cqp.setCurPage(pageParam);
					cqp.add();
					List<BnsLogEntity> allLogList = systemService.getListByCriteriaQuery(cqp, true);
					int pageCount=0;
					if(dataCount.intValue()>0 && dataCount.intValue()%10==0)
						pageCount=dataCount.intValue()/10;
					else
						pageCount=dataCount.intValue()/10+1;

					request.setAttribute("allLogList", allLogList);
					request.setAttribute("pageCount",pageCount); 
				}
				
				//############################# 添加日志  --zyb
				else if("rz_write".equals(what)){
					CriteriaQuery logclasscq = new CriteriaQuery(BnsLogClassEntity.class);
					logclasscq.eq("createBy", mymbId.toString());
					logclasscq.add();
					List<BnsLogClassEntity> myLogClass = systemService.getListByCriteriaQuery(logclasscq, false);
					if(myLogClass != null && myLogClass.size() > 0){
						request.setAttribute("myLogClass", myLogClass);
					}else
						request.setAttribute("myLogClass", "");
					
					String rz_title = request.getParameter("rz_title");
					String rz_content = request.getParameter("rz_content");
					String rz_class = request.getParameter("logc");

					if(rz_title != "" && rz_title != null && rz_content != "" && rz_content != null){
						BnsLogEntity myRzhi = new BnsLogEntity();
						myRzhi.setTitle(rz_title);
						myRzhi.setContent(rz_content);
						myRzhi.setCreateDate(new Date());
						myRzhi.setCreateBy(mymbId.toString());
						myRzhi.setCreateName(userName);
						myRzhi.setClassify(rz_class); 	//分类  --zyb
						myRzhi.setPlNum(0);  	//评论量  --zyb
						myRzhi.setReadNum(0);	//阅读量  --zyb
						bnsRizhiService.save(myRzhi);
						
						//保存一条动态
						BnsDtEntity dt = new BnsDtEntity();
						dt.setUser1Id(Integer.valueOf(mymbId.toString()));
						dt.setUser1Name(userName);
						dt.setTitle(rz_title);
						dt.setContent(rz_content);
						dt.setDtId(myRzhi.getId());		//保存日志id到动态对象id
						dt.setCreateDate(new Date());
						dt.setDtType("zxrz"); 			//动态类型：撰写日志
						bnsDtService.save(dt);
					}
				}
				else if("rz_friend".equals(what)){
					//好友日志	--zyb				
					List<Map<String, Object>> fLogs = systemService.findForJdbc("select * from bns_log where create_by = any(select friend_id from bns_user_friend where user_id = '"+mymbId+"' and is_gre = 1)");
					request.setAttribute("fLogs", fLogs);
					
				}
				
				/***************************  相册  --zyb ************************************/
				//上传图片
				else if("xc_write".equals(what)){
					String title = request.getParameter("xc_title");
					String xcId = request.getParameter("xcId");
					if(imgUrl != "" && imgUrl != null && xcId != null){
						//根据相册id查出相册名
						List<Map<String, Object>> alname = systemService.findForJdbc("select name from bns_album where id = '"+xcId+"'");
						String slcXcName = alname.get(0).get("name").toString();
//						System.out.print(slcAlbName);
						
						//照片
						BnsPhotoEntity pt = new BnsPhotoEntity();
						pt.setCreateDate(new Date());
						pt.setCreateBy(""+mymbId);
						pt.setCreateName(userName);
						pt.setTitle(title);
						pt.setAlbumId(xcId);
						pt.setAlbumName(slcXcName);
						pt.setImageUrl(imgUrl);
						pt.setBtJd(0);
						pt.setBtKb(0);
						pt.setBtLr(0);
						pt.setBtPl(0);
						pt.setBtXh(0);
						bnsPhotoService.save(pt);
						//相册
						BnsAlbumEntity alb = systemService.getEntity(BnsAlbumEntity.class, xcId);
						alb.setPhotoNum(alb.getPhotoNum() + 1);		//相册的图片数+1
						alb.setUpdateDate(new Date()); 				//更新时间
						alb.setCover(imgUrl);
						bnsAlbumService.save(alb);
						//保存一条动态
						BnsDtEntity dt = new BnsDtEntity();
						dt.setUser1Id(Integer.valueOf(mymbId.toString()));
						dt.setUser1Name(userName);
						dt.setTitle(title);
						dt.setContent(imgUrl);
						dt.setCreateDate(new Date());
						dt.setDtId(pt.getId()); //保存图片id到动态对象id
						dt.setDtType("sctp"); 	//动态类型：上传图片
						bnsDtService.save(dt);
												
					}
					//用于新上传图片页面的相册名显示
					CriteriaQuery alcq = new CriteriaQuery(BnsAlbumEntity.class);
					alcq.eq("createBy", mymbId.toString());
					alcq.add();
					List<BnsAlbumEntity> myAlbumList = systemService.getListByCriteriaQuery(alcq, false);
					request.setAttribute("myAlbumList", myAlbumList);
				}
				//相册--随便看看
				else if("xc_all".equals(what)){
					
					String ishot = request.getParameter("ishot");		//是否为热门图片
					
					if("y".equals(ishot)){
						//分页的相关参数  --zyb
						String page=request.getParameter("page");
						int pageParam=1;
						if(StringUtil.isEmpty(page))
							pageParam=1;
						else
							pageParam=Integer.parseInt(page);
						
						Long dataCount=0L;		//总共的数据数量
						int numInPage = 20;		//一页显示20个	--zyb
						List<Map<String, Object>> allPhotoList = systemService.findForJdbc("select * from bns_photo ORDER BY (bt_xh + bt_lr + bt_kb + bt_pl + bt_jd) DESC"
								, pageParam
								, numInPage);
											
						//分页 											
						dataCount = systemService.getCountForJdbcParam("select count(1) from bns_photo", null);
						int pageCount=0;
						if(dataCount.intValue()>0 && dataCount.intValue()%numInPage==0)
							pageCount=dataCount.intValue()/numInPage;
						else
							pageCount=dataCount.intValue()/numInPage+1;
						request.setAttribute("pageCount",pageCount); 
						
						
						request.setAttribute("allPhotoList", allPhotoList);
						
					}else{
						//分页的相关参数  --zyb
						String page=request.getParameter("page");
						int pageParam=0;
						if(StringUtil.isEmpty(page))
							pageParam=0;
						else
							pageParam=Integer.parseInt(page);				
						Long dataCount=0L;
						
						CriteriaQuery album_cq = new CriteriaQuery(BnsAlbumEntity.class);
						dataCount = systemService.getCountForJdbcParam("select count(1) from bns_album",null);
						
						//排序				
						album_cq.addOrder("updateDate", SortDirection.desc);
						//分页 
						int numInPage = 20;		//一页显示20个	--zyb
						album_cq.setPageSize(numInPage);
						album_cq.setCurPage(pageParam);
						album_cq.add();
						List<BnsAlbumEntity> allAlbList = systemService.getListByCriteriaQuery(album_cq, true);
						int pageCount=0;
						if(dataCount.intValue()>0 && dataCount.intValue()%numInPage==0)
							pageCount=dataCount.intValue()/numInPage;
						else
							pageCount=dataCount.intValue()/numInPage+1;
						
						request.setAttribute("pageCount",pageCount); 
						request.setAttribute("allAlbList", allAlbList);
					}						
					
				}
				//相册--我的相册
				else if("xc_my".equals(what)){
					
					//分页的相关参数  --zyb
					String page=request.getParameter("page");
					int pageParam=0;
					if(StringUtil.isEmpty(page))
						pageParam=0;
					else
						pageParam=Integer.parseInt(page);				
					Long dataCount=0L;
					
					CriteriaQuery album_cq = new CriteriaQuery(BnsAlbumEntity.class);
					dataCount = systemService.getCountForJdbcParam("select count(1) from bns_album where create_by = "+mymbId,null);
					album_cq.eq("createBy", mymbId.toString());
					album_cq.addOrder("updateDate", SortDirection.desc);
					//分页 
					int numInPage = 20;		//一页显示20个	--zyb
					album_cq.setPageSize(numInPage);
					album_cq.setCurPage(pageParam);
					album_cq.add();
					List<BnsAlbumEntity> myAlbList = systemService.getListByCriteriaQuery(album_cq, true);
					int pageCount=0;
					if(dataCount.intValue()>0 && dataCount.intValue()%numInPage==0)
						pageCount=dataCount.intValue()/numInPage;
					else
						pageCount=dataCount.intValue()/numInPage+1;
					request.setAttribute("pageCount",pageCount); 
					request.setAttribute("myAlbList", myAlbList);
				}
				//相册--好友相册
				else if("xc_friend".equals(what)){

					//分页的相关参数  --zyb
					String page=request.getParameter("page");
					int pageParam=1;
					if(StringUtil.isEmpty(page))
						pageParam=1;
					else
						pageParam=Integer.parseInt(page);
					
					Long dataCount=0L;		//总共的数据数量
					int numInPage = 5;		//一页显示20个	--zyb
					List<Map<String, Object>> fAlbList = systemService.findForJdbc("select * from bns_album where create_by = any(select friend_id from bns_user_friend where user_id = "+mymbId+" and is_gre = 1) ORDER BY update_date DESC"
							, pageParam
							, numInPage);
										
					//分页 											
					dataCount = systemService.getCountForJdbcParam("select count(1) from bns_album where create_by = any(select friend_id from bns_user_friend where user_id = '"+mymbId+"' and is_gre = 1)",null);
					int pageCount=0;
					if(dataCount.intValue()>0 && dataCount.intValue()%numInPage==0)
						pageCount=dataCount.intValue()/numInPage;
					else
						pageCount=dataCount.intValue()/numInPage+1;
					request.setAttribute("pageCount",pageCount); 
					
					
					request.setAttribute("fAlbList", fAlbList);
				}
				/***************************  分享  --zyb ************************************/
				//分享--随便看看
				else if("fx_all".equals(what)){
					
					String type = request.getParameter("type");	//分享类型
//					System.out.print(type);
					if(type == null){
						type = "";
					}else{
						type = " where type = '"+type+"'";
					}
					
					//分页的相关参数  --zyb
					String page=request.getParameter("page");					
					int pageParam=1;
					if(StringUtil.isEmpty(page))
						pageParam=1;
					else
						pageParam=Integer.parseInt(page);
					
					Long dataCount=0L;		//总共的数据数量
					int numInPage = 5;		//一页显示的个数	--zyb
					
					List<Map<String, Object>> allFxList = systemService.findForJdbc("SELECT * FROM bns_share " +type+ " ORDER BY create_date DESC", pageParam, numInPage);
					
					//分页 											
					dataCount = systemService.getCountForJdbcParam("select count(1) from bns_share"+type, null);
					int pageCount=0;
					if(dataCount.intValue()>0 && dataCount.intValue()%numInPage==0)
						pageCount=dataCount.intValue()/numInPage;
					else
						pageCount=dataCount.intValue()/numInPage+1;
					request.setAttribute("pageCount",pageCount); 
					request.setAttribute("allFxList", allFxList);						
					
	
				//分享--我的分享
				}else if("fx_my".equals(what)){
					
					String type = request.getParameter("type");	//分享类型
//					System.out.print(type);
					if(type == null){
						type = "";
					}else{
						type = " and type = '"+type+"'";
					}
					
					//分页的相关参数  --zyb
					String page=request.getParameter("page");
					int pageParam=1;
					if(StringUtil.isEmpty(page))
						pageParam=1;
					else
						pageParam=Integer.parseInt(page);
					
					Long dataCount=0L;		//总共的数据数量
					int numInPage = 5;		//一页显示的个数	--zyb
					
					List<Map<String, Object>> myFxList = systemService.findForJdbc("SELECT * FROM bns_share where create_by = "+mymbId+type+" ORDER BY create_date DESC",  pageParam, numInPage);
					
					//分页 											
					dataCount = systemService.getCountForJdbcParam("select count(1) from bns_share where create_by = "+mymbId+type+" ORDER BY create_date DESC",null);
					int pageCount=0;
					if(dataCount.intValue()>0 && dataCount.intValue()%numInPage==0)
						pageCount=dataCount.intValue()/numInPage;
					else
						pageCount=dataCount.intValue()/numInPage+1;
					request.setAttribute("pageCount",pageCount); 
					
					request.setAttribute("myFxList", myFxList);						
					
//					pathStr = ""
					
				//分享--好友的分享	
				}else if("fx_friend".equals(what)){
					
					String type = request.getParameter("type");	//分享类型
//					System.out.print(type);
					if(type == null){
						type = "";
					}else{
						type = " and type = '"+type+"'";
					}
					
					//分页的相关参数  --zyb
					String page=request.getParameter("page");
					int pageParam=1;
					if(StringUtil.isEmpty(page))
						pageParam=1;
					else
						pageParam=Integer.parseInt(page);
					
					Long dataCount=0L;		//总共的数据数量
					int numInPage = 5;		//一页显示的个数	--zyb
					
					List<Map<String, Object>> fFxList = systemService.findForJdbc("select * from bns_share where create_by = any(select friend_id from bns_user_friend where user_id = "+mymbId+type+" and is_gre = 1) ORDER BY create_date DESC",  pageParam, numInPage);
					
					//分页 											
					dataCount = systemService.getCountForJdbcParam("select count(1) from bns_share where create_by = any(select friend_id from bns_user_friend where user_id = "+mymbId+type+" and is_gre = 1)",null);
					int pageCount=0;
					if(dataCount.intValue()>0 && dataCount.intValue()%numInPage==0){
						pageCount=dataCount.intValue()/numInPage;
					}else{
						pageCount=dataCount.intValue()/numInPage+1;
						}
					request.setAttribute("pageCount",pageCount); 
					
					request.setAttribute("fFxList", fFxList);						
					
					
					
//				//分享--创建分享	
//				}else if("fx_write".equals(what)){
//					String fx_link = request.getParameter("fx_link");
//					String fx_mx = request.getParameter("fx_mx");
//					String type = null;		//分享类型
//					if( fx_link.endsWith("mp3") || fx_link.endsWith("wma") )
//						type = "yy";	//类型：音乐
//					else if( fx_link.endsWith("swf") )
//						type = "fl";	//类型：flash
//					else if( fx_link.contains("youku.com") || fx_link.contains("ku6.com")|| fx_link.contains("ouou.com")
//							|| fx_link.contains("56.com")|| fx_link.contains("tv.sohu.com")|| fx_link.contains("video.sina.com")){
//						type = "sp";	//类型：视频
//					}else
//						type = "wz";	//类型：网址
//					
//					BnsShareEntity wriShare = new BnsShareEntity();
//					wriShare.setTitle("");
//					wriShare.setContent(fx_link);
//					wriShare.setInfo(fx_mx);
//					wriShare.setType(type);
//					wriShare.setCreateBy(""+mymbId);
//					wriShare.setCreateName(userName);
//					wriShare.setCreateDate(new Date());
//					bnsShareService.save(wriShare);
//					
//					pathStr = "redirect:/indexController.do?home&show=fx_my";
				}
				/***************************  动态  --zyb ************************************/
				else if("dt_all".equals(what)){
					/**************** 动态-随便看看  *******************/
					//分页的相关参数  --zyb
					String page=request.getParameter("page");					
					int pageParam=1;
					if(StringUtil.isEmpty(page))
						pageParam=1;
					else
						pageParam=Integer.parseInt(page);
					
					Long dataCount=0L;		//总共的数据数量
					int numInPage = 8;		//一页显示的个数	--zyb
					
					List<Map<String, Object>> allDtList = systemService.findForJdbc("SELECT * FROM bns_dt ORDER BY create_date DESC", pageParam, numInPage);
					
					//分页 											
					dataCount = systemService.getCountForJdbcParam("select count(1) from bns_dt", null);
					int pageCount=0;
					if(dataCount.intValue()>0 && dataCount.intValue()%numInPage==0)
						pageCount=dataCount.intValue()/numInPage;
					else
						pageCount=dataCount.intValue()/numInPage+1;
					request.setAttribute("pageCount",pageCount); 
					request.setAttribute("allDtList", allDtList);		
				}
					
				else if("dt_my".equals(what)){
					/**************** 动态-我的动态  *******************/
					//分页的相关参数  --zyb
					String page=request.getParameter("page");
					
					int pageParam=1;
					if(StringUtil.isEmpty(page))
						pageParam=1;
					else
						pageParam=Integer.parseInt(page);
					
					Long dataCount=0L;		//总共的数据数量
					int numInPage = 8;		//一页显示的个数	--zyb
					
					List<Map<String, Object>> myDtList = systemService.findForJdbc("SELECT * FROM bns_dt where user1_id = " +mymbId+ " ORDER BY create_date DESC", pageParam, numInPage);
					
					//分页 											
					dataCount = systemService.getCountForJdbcParam("select count(1) from bns_dt where user1_id = "+mymbId, null);
					int pageCount=0;
					if(dataCount.intValue()>0 && dataCount.intValue()%numInPage==0)
						pageCount=dataCount.intValue()/numInPage;
					else
						pageCount=dataCount.intValue()/numInPage+1;
					request.setAttribute("pageCount",pageCount); 
					request.setAttribute("myDtList", myDtList);		
				}
				
				else if("dt_friend".equals(what)){
					/**************** 动态-好友动态  *******************/
					//分页的相关参数  --zyb
					String page=request.getParameter("page");
					String wfDt = request.getParameter("wfDt");		//好友分组
					String wfSql = "";								//好友分组的sql语句
					if(wfDt == null){
						wfSql = "";
					}else{
						wfSql = " and fz = " +wfDt;
					}
					
					int pageParam=1;
					if(StringUtil.isEmpty(page))
						pageParam=1;
					else
						pageParam=Integer.parseInt(page);
					
					Long dataCount=0L;		//总共的数据数量
					int numInPage = 8;		//一页显示的个数	--zyb
					
					List<Map<String, Object>> fDtList = systemService.findForJdbc("SELECT * FROM bns_dt where user1_id = any(select friend_id from bns_user_friend where user_id = "+mymbId+wfSql+" and is_gre = 1) ORDER BY create_date DESC", pageParam, numInPage);
					
					//分页 											
					dataCount = systemService.getCountForJdbcParam("select count(1) from bns_dt where user1_id = any(select friend_id from bns_user_friend where user_id = "+mymbId+wfSql+" and is_gre = 1)", null);
					int pageCount=0;
					if(dataCount.intValue()>0 && dataCount.intValue()%numInPage==0)
						pageCount=dataCount.intValue()/numInPage;
					else
						pageCount=dataCount.intValue()/numInPage+1;
					request.setAttribute("pageCount",pageCount); 
					request.setAttribute("fDtList", fDtList);		
				}
				
				

				//我的相册、说说、日志数量
				long myLogNum = systemService.getCountForJdbcParam("select count(1) from bns_log where create_by = '"+mymbId+"'",null);
				request.setAttribute("myLogNum", myLogNum);
				long mySsNum = systemService.getCountForJdbcParam("select count(1) from bns_shuoshuo where create_by = '"+mymbId+"'",null);
				request.setAttribute("mySsNum", mySsNum);
				long myAlbumNum = systemService.getCountForJdbcParam("select count(1) from bns_album where create_by = '"+mymbId+"'",null);
				request.setAttribute("myAlbumNum", myAlbumNum);
				long myFxNum = systemService.getCountForJdbcParam("select count(1) from bns_share where create_by = '"+mymbId+"'",null);
				request.setAttribute("myFxNum", myFxNum);
				
				//分享量
				long shareNum = systemService.getCountForJdbcParam("select count(1) from bns_share",null);
				request.setAttribute("shareNum", shareNum);
		}
//		model.addAttribute("page", 1);
//		model.addAttribute("pageCount", 1);
		model.addAttribute("backgroundColor", "3");
		return new ModelAndView(pathStr);
	}
	/**
	 * 添加日志分类页面跳转
	 * @return
	 */
	@RequestMapping(params = "addRzClass")
	public ModelAndView addRzClass(Model model,HttpServletRequest request) {
		Object mymbId= request.getSession().getAttribute("mbId");
		String userName = (String) request.getSession().getAttribute("userName");
		String pathStr = "front/addRzClass";
		AjaxJson j = new AjaxJson();
		
		//判断登录是否超时  --zyb
		if(!StringUtil.isNotEmpty(mymbId)){	
			userName = "";
			pathStr = "front/login";	
		}else{}	
		
		
		return new ModelAndView(pathStr);
	}

	
	/**
	 * 保存日志分类
	 * @return
	 */
	@RequestMapping(params = "saveRzClass")
	public AjaxJson saveRzClass(HttpServletRequest request, HttpServletResponse response) {
		Object mymbId= request.getSession().getAttribute("mbId");
		String userName = (String) request.getSession().getAttribute("userName");
		String className = request.getParameter("className");
		String pathStr = "front/addRzClass";
		AjaxJson j = new AjaxJson();
		message = "添加成功";
		//判断登录是否超时  --zyb
		if(!StringUtil.isNotEmpty(mymbId)){	
			userName = "";
			j.setMsg("请登录");
			return j;	
		}else{
			//保存日志
			BnsLogClassEntity myLogClass = new BnsLogClassEntity();
			myLogClass.setCreateDate(new Date());
			myLogClass.setCreateBy(mymbId.toString());
			myLogClass.setCreateName(userName);
			myLogClass.setClassifyName(className);
			bnsLogClassService.save(myLogClass);
			
			
		}	
		j.setMsg(message);
		j.setSuccess(true);
		return j;
		
	}
	
	/**
	 * 日志详情页面跳转
	 * @return
	 */
	@RequestMapping(params = "logInfo")
	public ModelAndView logInfo(Model model,HttpServletRequest request) {
		String pathStr = "front/logInfo";
		Object mymbId= request.getSession().getAttribute("mbId");
		String userName = (String) request.getSession().getAttribute("userName");
		String creBy = null;	//日志的作者  --zyb
		
		//判断登录是否超时  --zyb
		if(!StringUtil.isNotEmpty(mymbId)){	
			userName = "";
			pathStr = "front/login";	
		}else{
			//获取日志id  --zyb
			String logId = request.getParameter("logId");
			if(StringUtil.isNotEmpty(logId)){
				CriteriaQuery cqs = new CriteriaQuery(BnsLogEntity.class);
				cqs.eq("id", logId);
				cqs.add();
				List<BnsLogEntity> myLogList = systemService.getListByCriteriaQuery(cqs, false);
				//阅读量+1  --zyb
				BnsLogEntity myLog = bnsRizhiService.getEntity(BnsLogEntity.class, logId);
				myLog.setReadNum(myLog.getReadNum() + 1);
				bnsRizhiService.save(myLog);
				
				if(myLogList!=null && myLogList.size()>0){
					request.setAttribute("myLogList", myLogList.get(0));
					creBy = myLogList.get(0).getCreateBy();
				}else
					request.setAttribute("myLogList","");
				
					//######################## 评论  --zyb
					String rzCom = request.getParameter("rzCom");
					String rzId= request.getParameter("rzId");
	//				System.out.print("--------------------rzCom:"+rzCom);
					if(rzCom != "" && rzCom != null){
						//添加评论  --zyb
						BnsArticleCommentsEntity logCom = new BnsArticleCommentsEntity();
						logCom.setCommentsType("0");
						logCom.setCommentsId("");
						logCom.setReplyTitle("");
						logCom.setReplyContent("");
						logCom.setArticleId(rzId);
						logCom.setCommentsContent(rzCom);				
						logCom.setCreateDate(new Date());
						logCom.setCreateBy(mymbId.toString());
						logCom.setCreateName(userName);
						//日志评论数+1  --zyb
						bnsRzCommentsService.save(logCom);
						BnsLogEntity plLog = bnsRizhiService.getEntity(BnsLogEntity.class, rzId);
						plLog.setPlNum(plLog.getPlNum() + 1);
						bnsRizhiService.save(plLog);
					}
				
					//评论列表  --zyb
					CriteriaQuery comcq = new CriteriaQuery(BnsArticleCommentsEntity.class);
					comcq.eq("articleId", logId);
					comcq.add();
					List<BnsArticleCommentsEntity> comList = systemService.getListByCriteriaQuery(comcq, true);
					if(comList!=null && comList.size()>0)
						request.setAttribute("comList", comList);
					else
						request.setAttribute("comList","");	
					
					//最新日志  --zyb
					if(StringUtil.isNotEmpty(creBy) && creBy != ""){
						CriteriaQuery newlogcq = new CriteriaQuery(BnsLogEntity.class);
						newlogcq.eq("createBy",creBy);
						newlogcq.addOrder("createDate", SortDirection.desc);
						newlogcq.add();
						List<BnsLogEntity> newLogList = systemService.getListByCriteriaQuery(newlogcq, false);
						if(newLogList != null && newLogList.size() > 0){
							request.setAttribute("newLogList", newLogList);
						}else
							request.setAttribute("newLogList", "");
					}
				
			}
			
		
		}	
		
		return new ModelAndView(pathStr);
	}
	
	/**
	 * 添加好友页面跳转
	 */
	@RequestMapping(params = "goAddFriend")
	public ModelAndView goAddFriend(HttpServletRequest request, HttpServletResponse response){
		
		String path = "front/login";
		HttpSession session = request.getSession();
		AjaxJson j = new AjaxJson();
		String mbId = "";
		Object mbIdV = session.getAttribute("mbId");
		String fId = request.getParameter("fId");
		request.setAttribute("fId", fId);
		String fName = request.getParameter("fName");
		request.setAttribute("fName", fName);
		if (!StringUtil.isNotEmpty(mbIdV)) {
			return new ModelAndView(path);
		}
//		String userName = session.getAttribute("userName").toString();
//		
//		// try {
//		mbId = mbIdV.toString();
//		
//		String articleId = request.getParameter("articleId");
//		
//		
//		BnsArticleEntity articleInfo = systemService.getEntity(BnsArticleEntity.class, articleId);
//		
//		request.setAttribute("articleInfo",articleInfo);
		return new ModelAndView("front/addFriend");
	}
	
	/**
	 * 保存好友
	 * 
	 * @param saveReply
	 * @param request
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping(params = "saveFriend")
	@ResponseBody
	public AjaxJson saveFriend( HttpServletRequest request) throws Exception{
		String path = "front/login";		
		HttpSession session = request.getSession();
		BnsUsersInfoEntity userInfo = (BnsUsersInfoEntity)session.getAttribute("LOCAL_FRONT_USER");
		int mId_int = userInfo.getUserId();
		String mName = userInfo.getUserName();
		int fId_int = 0;
			
		String fId = request.getParameter("fId");
		String fFz = request.getParameter("fFz");
		String fy = request.getParameter("fy");
		
		AjaxJson j = new AjaxJson();
		if (!StringUtil.isNotEmpty(mId_int)) {
			j.setMsg("请登录");
			return j;
		}else {			
			fId_int = Integer.parseInt(String.valueOf(fId));
			if(fId_int == mId_int){
				j.setMsg("不能申请自己为好友！");
				j.setSuccess(false);
				return j;	
			}
			//第一条好友记录
			BnsUserFriendEntity uFriend = new BnsUserFriendEntity();
			uFriend.setCreateDate(new Date());
			uFriend.setUserId(mId_int);
			uFriend.setFriendId(fId_int);
			uFriend.setFz(fFz);
			uFriend.setFy(fy);
			uFriend.setIsGre(0);
			bnsUserFriendService.save(uFriend);
			//第二条好友记录（用户id和好友id相反，便于好友关系的查询） --zyb
			BnsUserFriendEntity uFriend2 = new BnsUserFriendEntity();
			uFriend2.setCreateDate(new Date());
			uFriend2.setUserId(fId_int);
			uFriend2.setFriendId(mId_int);
			uFriend2.setFz(fFz);
			uFriend2.setFy(fy);
			uFriend2.setIsGre(0);
			bnsUserFriendService.save(uFriend2);
			//添加一条消息记录
			BnsMessageEntity fMsg = new BnsMessageEntity();
			fMsg.setTitle("好友申请");
			fMsg.setCreateBy(""+mId_int);
			fMsg.setCreateName(mName);
			fMsg.setReceiveId(""+fId_int);
			fMsg.setMessageTypes(3);
			fMsg.setContent(mName+"请求添加您为好友！");
			fMsg.setCreateDate(new Date());
			fMsg.setIsRead("N");
			fMsg.setStates("Y");
			bnsMessageService.save(fMsg);
		}
			j.setMsg("已申请，等待好友确定");
			j.setSuccess(true);
			return j;	
	}
	
	
	
	
	
	
	/**
	 * 新建相册页面跳转
	 */
	@RequestMapping(params = "goAddAlbum")
	public ModelAndView goAddAlbum(HttpServletRequest request, HttpServletResponse response){
		
		String path = "front/login";
		HttpSession session = request.getSession();
		AjaxJson j = new AjaxJson();
		String mbId = "";
		Object mbIdV = session.getAttribute("mbId");
		
		if (!StringUtil.isNotEmpty(mbIdV)) {
			return new ModelAndView(path);
		}
//		String userName = session.getAttribute("userName").toString();
//		
//		// try {
//		mbId = mbIdV.toString();
//		
//		String articleId = request.getParameter("articleId");
//		
//		
//		BnsArticleEntity articleInfo = systemService.getEntity(BnsArticleEntity.class, articleId);
//		
//		request.setAttribute("articleInfo",articleInfo);
		return new ModelAndView("front/addAlbum");
	}
	
	/**
	 * 保存相册
	 * 
	 * @param saveReply
	 * @param request
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping(params = "saveAlbum")
	@ResponseBody
	public AjaxJson saveAlbum( HttpServletRequest request) throws Exception{
		String path = "front/login";
		HttpSession session = request.getSession();
		String mbId = "";
		Object mbIdV = session.getAttribute("mbId");
		String userName = (String) request.getSession().getAttribute("userName");
		String aName = request.getParameter("aName");
		String xcfw = request.getParameter("xcfw");
		
		AjaxJson j = new AjaxJson();
		if (!StringUtil.isNotEmpty(mbIdV)) {
			j.setMsg("请登录");
			return j;
		}else {
			BnsAlbumEntity myAlbum = new BnsAlbumEntity();
			myAlbum.setCreateBy(mbIdV.toString());
			myAlbum.setCreateName(userName);
			myAlbum.setCreateDate(new Date());
			myAlbum.setUpdateDate(new Date()); 	//创建相册时，更新时间与创建时间一样，防止未上传照片时，无更新时间
			myAlbum.setName(aName);
			myAlbum.setXcfw(xcfw);
			myAlbum.setPhotoNum(0);		
			bnsAlbumService.save(myAlbum);
			
			
		}
		
		
		j.setMsg("新建相册成功！");
		j.setSuccess(true);
		return j;	
	}
	
	
	/**
	 * 保存分享
	 * 
	 * @param saveReply
	 * @param request
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping(params = "saveShare")
	@ResponseBody
	public AjaxJson saveShare(HttpServletRequest request) throws Exception{
//		String path = "front/login";
		HttpSession session = request.getSession();
//		String mbId = "";
		BnsUsersInfoEntity userInfo = (BnsUsersInfoEntity)session.getAttribute("LOCAL_FRONT_USER");
		
		String fx_link = request.getParameter("fx_link");
		String fx_mx = request.getParameter("fx_mx");
		String fx_link2 = request.getParameter("fx_link2");
		String fx_mx2 = request.getParameter("fx_mx2");	
		//说明：此处fx_mx2为分享弹窗的“描述”内容，优先级较高，所以非空时覆盖fx_mx
		if(fx_mx2 != null && fx_mx2 != ""){
			fx_link = fx_link2;
			fx_mx = fx_mx2;
		}
		
		String type = null;		//分享类型
		if( fx_link.endsWith("mp3") || fx_link.endsWith("wma") )
			type = "yy";	//类型：音乐
		else if( fx_link.endsWith("swf") )
			type = "fl";	//类型：flash
		else if( fx_link.contains("youku.com") || fx_link.contains("ku6.com")|| fx_link.contains("ouou.com")
				|| fx_link.contains("56.com")|| fx_link.contains("tv.sohu.com")|| fx_link.contains("video.sina.com")){
			type = "sp";	//类型：视频
		}else
			type = "wz";	//类型：网址
		
		
		AjaxJson j = new AjaxJson();
		if (!StringUtil.isNotEmpty(userInfo.getUserId())) {
			j.setMsg("请登录");
			return j;
		}else {
			if(fx_link == ""){
				j.setMsg("请输入您要分享的内容！");
				j.setSuccess(false);
				return j;	
			}
			if(fx_mx == ""){
				j.setMsg("请输入描述！");
				j.setSuccess(false);
				return j;	
			}else if(fx_mx.length() > 200){
				j.setMsg("描述过多，请重新输入！");
				j.setSuccess(false);
				return j;	
			}
			
			BnsShareEntity wriShare = new BnsShareEntity();
			wriShare.setTitle("");
			wriShare.setContent(fx_link);
			wriShare.setInfo(fx_mx);
			wriShare.setType(type);
			wriShare.setCreateBy(""+userInfo.getUserId());
			wriShare.setCreateName(userInfo.getUserName());
			wriShare.setCreateDate(new Date());
			bnsShareService.save(wriShare);
			
			//保存一条动态
			BnsDtEntity fxdt = new BnsDtEntity();
			fxdt.setUser1Id(userInfo.getUserId());
			fxdt.setUser1Name(userInfo.getUserName());
			fxdt.setTitle(fx_link);
			fxdt.setContent(fx_mx);
			fxdt.setCreateDate(new Date());
			fxdt.setDtId(wriShare.getId()); //保存分享id到动态对象id
			fxdt.setDtType("tjfx"); 	//动态类型：添加分享
			bnsDtService.save(fxdt);
			
			j.setMsg("分享成功！");
			j.setSuccess(true);
			return j;	
		}
						
	}
	
	
	/**
	 * 保存评论
	 * 
	 * @param saveReply
	 * @param request
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping(params = "savePl")
	@ResponseBody
	public AjaxJson savePl(HttpServletRequest request) throws Exception{
//		String path = "front/login";
		HttpSession session = request.getSession();
//		String mbId = "";
		BnsUsersInfoEntity userInfo = (BnsUsersInfoEntity)session.getAttribute("LOCAL_FRONT_USER");
		
		String plId = request.getParameter("pl_id");		//被评论的分享id
		String plCon = request.getParameter("plCon");		//评论的内容
		
							
		AjaxJson j = new AjaxJson();
		if (!StringUtil.isNotEmpty(userInfo.getUserId())) {
			j.setMsg("请登录");
			return j;
		}else {
			if(plCon == ""){
				j.setMsg("请输入评论内容！");
				j.setSuccess(false);
				return j;	
			}
			
			BnsArticleCommentsEntity pl = new BnsArticleCommentsEntity();
			pl.setCreateBy(""+userInfo.getUserId());
			pl.setCreateName(userInfo.getUserName());
			pl.setArticleId(plId);
			pl.setCommentsContent(plCon);
			pl.setCommentsType("0");
			bnsArtComService.save(pl);
			
			j.setMsg("评论成功！");
			j.setSuccess(true);
			return j;	
		}
						
	}
	
	
	/**
	 * 淘贴
	 * @return
	 */
	@RequestMapping(params = "taoTie")
	public ModelAndView taoTie(Model model,HttpServletRequest request) {
		String pathStr = "front/taoTie";
		model.addAttribute("backgroundColor", "4");
		return new ModelAndView(pathStr);
	}
	
	
	
	/**
	 * 在线批八字算命
	 * @return
	 */
	@RequestMapping(params = "suanMing")
	public ModelAndView suanMing(Model model,HttpServletRequest request) {
		String pathStr = "front/suanMing";
		model.addAttribute("backgroundColor", "5");
		return new ModelAndView(pathStr);
	}
	
	/**
	 * 在线排盘
	 * @return
	 */
	@RequestMapping(params = "paiPan")
	public ModelAndView paiPan(Model model,HttpServletRequest request) {
		String pathStr = "front/paiPan";
		model.addAttribute("backgroundColor", "6");
		return new ModelAndView(pathStr);
	}
	

	
}
